package edu.sdjzu.exam.mapper;

import edu.sdjzu.exam.domain.auth.Permission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface PermissionMapper {
    @Select("SELECT * FROM Permissions WHERE permission_id = #{permissionId}")
    Permission findById(Long permissionId);

    @Select("SELECT * FROM Permissions WHERE permission_name = #{permissionName}")
    Permission findByName(String permissionName);

    @Insert("INSERT INTO Permissions (permission_name, description) VALUES (#{permissionName}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "permissionId")
    void insert(Permission permission);

    @Update("UPDATE Permissions SET permission_name = #{permissionName}, description = #{description} WHERE permission_id = #{permissionId}")
    void update(Permission permission);

    @Delete("DELETE FROM Permissions WHERE permission_id = #{permissionId}")
    void delete(Long permissionId);

    @Select("SELECT * FROM Permissions")
    List<Permission> findAll();
}
